package com.hgxd.entity.authentication;

import com.hgxd.utils.security.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author wtf
 * @create 2023-07-24 17:43
 * @description : 对spring security中的密码进行校验
 */
@Component
public class CustomMd5PasswordEncoder implements PasswordEncoder {
    /**
     * 密码加密
     * @param rawPwd
     * @return
     */
    @Override
    public String encode(CharSequence rawPwd) {
        return MD5.encrypt(rawPwd.toString());
    }

    /**
     * 校验密码
     * @param rawPwd 输入前端密码
     * @param pwd 数据库加密密码
     * @return
     */
    @Override
    public boolean matches(CharSequence rawPwd, String pwd) {
        return encode(rawPwd).equals(pwd);
    }
}

